package org.liufeng.weixin.main;

import org.liufeng.weixin.pojo.AccessToken;
import org.liufeng.weixin.pojo.Button;
import org.liufeng.weixin.pojo.CommonButton;
import org.liufeng.weixin.pojo.ComplexButton;
import org.liufeng.weixin.pojo.Menu;
import org.liufeng.weixin.pojo.ViewButton;
import org.liufeng.weixin.util.WeixinUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 菜单管理器类
 * 
 * @author liufeng
 * @date 2013-08-08
 */
public class MenuManager {
	//private static Logger log = LoggerFactory.getLogger(MenuManager.class);

	public static void main(String[] args) {
		//水利局服务号
		// 第三方用户唯一凭证
		//String appId = "wxe6b985ec7f7f39e7";
		
		// 第三方用户唯一凭证密钥
		//String appSecret = "e59dc003c9532db72a8f8b6e9917ce54";
		
		
		
		//莼湖水利站订阅号
		//String appId = "wxec7fa6b0a2c0a700";
		//String appSecret = "72fce37ae5434cf61c587e150f6e34e9";
		
		
		
		//莼湖水利站服务号
		String appId = "wxa40a7100041b5699";
		String appSecret = "b49b6ef5db35a3bab13ee7cf8d846ffd";
		
		
		// 调用接口获取access_token
		AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);

		if (null != at) {
			// 调用接口创建菜单
			int result = WeixinUtil.createMenu(getMenu(), at.getToken());

			// 判断菜单创建结果
			if (0 == result){
				System.out.print("菜单创建成功！");
			}
				//log.info("菜单创建成功！");
			else{
				System.out.print("菜单创建失败，错误码："+result);
			}
				//log.info("菜单创建失败，错误码：" + result);
			
			
		}
		
	}


	
	
	/**
	 * 组装菜单数据
	 * 
	 * @return
	 */
	private static Menu getMenu() {
		ViewButton btn11 = new ViewButton();
		btn11.setName("水库查询");
		btn11.setType("view");
		btn11.setUrl("http://fhsljchslz.duapp.com/fhsljwx/reser.jsp");  
	//	btn11.setUrl("http://niufox.gicp.net/reser.jsp"); 

		ViewButton btn12 = new ViewButton();
		btn12.setName("水闸查询");
		btn12.setType("view");
		btn12.setUrl("http://fhsljchslz.duapp.com/fhsljwx/gate.jsp");

		ViewButton btn13 = new ViewButton();
		btn13.setName("海塘查询");
		btn13.setType("view");
		btn13.setUrl("http://fhsljchslz.duapp.com/fhsljwx/pond.jsp");

//		ViewButton btn14 = new ViewButton();
//		btn14.setName("河道水位");
//		btn14.setType("view");
//		btn14.setUrl("http://fhsljchslz.duapp.com/fhsljwx/waterLevel.jsp");
		
		CommonButton btn14 = new CommonButton();
		btn14.setName("水位潮位");
		btn14.setType("click");
		btn14.setKey("14");

		
		CommonButton btn15 = new CommonButton();
		btn15.setName("雨情信息");
		btn15.setType("click");
		btn15.setKey("15");

		
		CommonButton btn21 = new CommonButton();
		btn21.setName("天气预报");
		btn21.setType("click");
		btn21.setKey("21");

		CommonButton btn22 = new CommonButton();
		btn22.setName("天气预警");
		btn22.setType("click");
		btn22.setKey("22");

		CommonButton btn23 = new CommonButton();
		btn23.setName("卫星云图");
		btn23.setType("click");
		btn23.setKey("23");

		CommonButton btn24 = new CommonButton();
		btn24.setName("台风动态");
		btn24.setType("click");
		btn24.setKey("24");

		ViewButton btn25 = new ViewButton();
		btn25.setName("空气质量");
		btn25.setType("view");
		btn25.setUrl("http://m.cnpm25.cn/pm/ningbo.html");

		CommonButton btn31 = new CommonButton();
		btn31.setName("工作动态");
		btn31.setType("click");
		btn31.setKey("31");

		ViewButton btn32 = new ViewButton();
		btn32.setName("防汛科普");
		btn32.setType("view");
		btn32.setUrl("http://fhsljchslz.duapp.com/fhsljwx/fxkp.jsp");

		ViewButton btn33 = new ViewButton();
		btn33.setName("查询帮助");
		btn33.setType("view");
		btn33.setUrl("http://fhsljchslz.duapp.com/fhsljwx/help.jsp");  
		
		CommonButton btn34 = new CommonButton();
		btn34.setName("建议咨询");
		btn34.setType("click");
		btn34.setKey("34");
		
		
		CommonButton btn35 = new CommonButton();
		btn35.setName("群众路线");
		btn35.setType("click");
		btn35.setKey("35");
		
		//ViewButton btn35 = new ViewButton();
		//btn35.setName("空气质量");
		//btn35.setType("view");
		//btn35.setUrl("http://m.cnpm25.cn/pm/ningbo.html"); 

		ComplexButton mainBtn1 = new ComplexButton();
		mainBtn1.setName("水雨工情");
		mainBtn1.setSub_button(new Button[] { btn11, btn12, btn13, btn14 ,btn15});

		ComplexButton mainBtn2 = new ComplexButton();
		mainBtn2.setName("防台防汛");
		mainBtn2.setSub_button(new Button[] { btn21, btn22, btn23, btn24, btn25 });

		ComplexButton mainBtn3 = new ComplexButton();
		mainBtn3.setName("其他相关");
		mainBtn3.setSub_button(new Button[] { btn31, btn32, btn33 ,btn34,btn35});

		/**
		 * 这是公众号xiaoqrobot目前的菜单结构，每个一级菜单都有二级菜单项<br>
		 * 
		 * 在某个一级菜单下没有二级菜单的情况，menu该如何定义呢？<br>
		 * 比如，第三个一级菜单项不是“更多体验”，而直接是“幽默笑话”，那么menu应该这样定义：<br>
		 * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 });
		 */
		Menu menu = new Menu();
		menu.setButton(new Button[] { mainBtn1, mainBtn2, mainBtn3 });

		return menu;
	}
}
